package com.nt.train.config.properties;

import com.nt.train.dto.Dog;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 想获取配置信息，必须是容器中的bean，其实和bean初始化逻辑一种，配置文件的信息其实就是属性填充
 * @ConfigurationProperties 告诉Spring对象的值从配置文件中获取，prefix前缀表示从配置文件中哪个配置项下面获取属性值
 * 自动必须要有get/set方法，否则无法完成属性填充（其实属性就是字段+get/set方法）
 * @author hlf
 * @version 1.0
 * @date 2022/8/9 10:54
 */
@Component
public class Person2 {
    /**
     * 1. @Value类似于bean标签中的value配置;
     * 2. bean中的value可以配置：字面量;${key}获取环境变量、配置文件中的key值,#{SpEl}spring的EL表达式;
     * 因此@Value也可以配置上面的三种值。
     * 3. @Value获取配置信息,可以不写get/set方法。
     * <bean id = "person" class="xxxxx">
     *     <property name="address" value="xxx"></property>
     * </bean>
     */
    @Value("小明")
    private String name;

    @Value("#{11*2}")
    private int age;

    @Value("${person.address}")
    private String address;

    private List<Object> like;

    private Map<String, Object> maps;

    private Dog dog;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public List<Object> getLike() {
        return like;
    }
    public void setLike(List<Object> like) {
        this.like = like;
    }
    public Map<String, Object> getMaps() {
        return maps;
    }
    public void setMaps(Map<String, Object> maps) {
        this.maps = maps;
    }
    public Dog getDog() {
        return dog;
    }
    public void setDog(Dog dog) {
        this.dog = dog;
    }
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                ", like=" + like +
                ", maps=" + maps +
                ", dog=" + dog +
                '}';
    }
}

